<?php

namespace apiend\modules\user\models;

use Yii;
use common\models\user\UserAddress;
use common\base\ModelHttpException;
use common\models\user\UserIm;

class RongCloudTokenForm extends \common\base\Model {

    /**
     * @var integer 用户UID
     */
    public $user_id;

    /**
     * @name $_model
     */
    private $_model = null;

    public function rules() {
        return [
            [['user_id'], 'required'],
            [['user_id'], 'integer'],
        ];
    }

    /**
     * 保存动态信息（发布&修改）
     * @param [type] $data
     * @return void
     */
    public function token() {
        if (!$this->validate()) {
            return $this->dumpError('参数校验失败');
        }
        $token = UserIm::findOrRegister($this->user_id);
        if ($token) {
            return [
                'rongyun_token' => $token,
            ];
        }
        return $token;
    }

}
